import { _decorator, Label, Sprite, Widget } from 'cc';
import { CfgSkillInfo } from '../config/CfgSkillInfo';
import { Bundle } from '../enum/Bundle';
import { SkillType } from '../enum/SkillType';
import { AdMgr } from '../manager/AdMgr';
import { GameMgr } from '../manager/GameMgr';
import { ResMgr } from '../manager/ResMgr';
import { SkillMgr } from '../manager/SkillMgr';
import { UIBase } from '../scriptBase/UIBase';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('UIGetSkill')
@requireComponent(Widget)
export class UIGetSkill extends UIBase {
    // @property({ type: Sprite })
    private icon: Sprite = null!
    // @property({ type: Label })
    private lbTitle: Label = null!
    // @property({ type: Label })
    private lbDesc: Label = null!

    private skill: SkillType = null

    protected onLoad(): void {
        // this.icon = this.findComp('Icon', Sprite)
        // this.lbTitle = this.findComp('LbTitle', Label)
        // this.lbDesc = this.findComp('LbDesc', Label)

        this.icon = this.node.getChildByName('Icon').getComponent(Sprite);
        this.lbTitle = this.node.getChildByName('LbTitle').getComponent(Label); 
        this.lbDesc = this.node.getChildByName('LbDesc').getComponent(Label);
    }

    public onOpen(data?: unknown): void {
        GameMgr.Pause = true
        this.skill = data as SkillType
        const skillInfo = CfgSkillInfo[this.skill]
        this.lbTitle.string = skillInfo.name
        this.lbDesc.string = skillInfo.desc
        this.icon.spriteFrame = ResMgr.getSpriteFrame(Bundle.Icon, skillInfo.icon)
    }

    public onClose(data?: unknown): void {
        GameMgr.Pause = false
    }

    protected onBtnGetClick(): void {
        AdMgr.showRewardedVideo(() => {
            SkillMgr.addSkill(this.skill)
            this.close()
        })
    }

}


